export default {
    install(Vue) {
        Vue.prototype.getMethod = function (url, method, data, callback) {
            this.$http({
                url,
                method,
                data,
            }).then((res) => {
                console.log(res);
                if (this.checkCode(res.status)) {
                    callback(res.data)
                } else {
                    this.showMessage("操作失败", 'error');
                }
            }).catch((err)=>{
                this.showMessage("操作失败", 'error');
            })
        };
        Vue.prototype.checkCode = function (code) {
            if (code >= 200 && code < 400) {
                return true;
            }else{
                return false;
            }
        };
        Vue.prototype.showMessage = function (msg, type) {
            this.$message({
                showClose: true,
                message: msg,
                type: type,
                duration: 1500
            })
        };
        Vue.prototype.showConfirm = function (msg, title, type, callback) {
            this.$confirm(msg, title, {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: type
            }).then(() => {
                callback();
            }).catch(error => {
                console.log(error);
            });
        }
        Vue.prototype.checkEmpty = function (data, msg) {
            if (!data) {
                if(msg) this.showMessage(msg + "不能为空", "error");
                return true;
            }
            return false;
        }
        Vue.prototype.isStrEmpty = function(obj){
            if(obj==null || obj=='undefined' || obj == ''){
                return true;
            }else{
                return false;
            }
        }
        Vue.prototype.checkObject = function(obj){
            let str =''
            for(let key in obj){
                if(obj[key]){
                    str += `&${key}=${obj[key]}`;
                }
            }
            return str
        }
        Vue.prototype.clearObj = function(obj){
            Object.keys(obj).forEach(key => obj[key] = '');
        }
    }
}